import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;


public class Loading_Panel extends JPanel  implements MouseListener, MouseMotionListener, ActionListener {
	
	private PanelListener listener;
	
	//1920
	private int width=0;
	//1080
	private int height=0;
	
	private Image[] imageList = new Image[13];
	
	private Timer timer;
	
	private int position=0;
	
	private int t_count=0;
	
	public Loading_Panel(int width, int height){
		
		this.width=width;
		this.height=height;
		
		imageList[0]=new ImageIcon(getClass().getResource("images/loading/background.png")).getImage();
		imageList[1]=new ImageIcon(getClass().getResource("images/loading/1.png")).getImage();
		imageList[2]=new ImageIcon(getClass().getResource("images/loading/2.png")).getImage();
		imageList[3]=new ImageIcon(getClass().getResource("images/loading/3.png")).getImage();
		imageList[4]=new ImageIcon(getClass().getResource("images/loading/4.png")).getImage();
		imageList[5]=new ImageIcon(getClass().getResource("images/loading/5.png")).getImage();
		imageList[6]=new ImageIcon(getClass().getResource("images/loading/6.png")).getImage();
		imageList[7]=new ImageIcon(getClass().getResource("images/loading/7.png")).getImage();
		imageList[8]=new ImageIcon(getClass().getResource("images/loading/8.png")).getImage();
		imageList[9]=new ImageIcon(getClass().getResource("images/loading/9.png")).getImage();
		imageList[10]=new ImageIcon(getClass().getResource("images/loading/10.png")).getImage();
		imageList[11]=new ImageIcon(getClass().getResource("images/loading/11.png")).getImage();
		imageList[12]=new ImageIcon(getClass().getResource("images/loading/12.png")).getImage();
		
		addMouseListener(this);
		addMouseMotionListener(this);
	  	Dimension size = new Dimension(width, height);
		setPreferredSize(size);
		setMinimumSize(size);
		setMaximumSize(size);
		setSize(size);
		setLayout(null);
		
		timer = new Timer(50, this);
		timer.start();
	}
	  

	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		
		//background
		g.drawImage(imageList[0], 0, 0, null);
		
		//message
		//799, 740
		g.drawImage(imageList[1+position], 837, 417, null);
		
	}
	
	public void mousePressed(MouseEvent e) {
		
    }

    public void mouseReleased(MouseEvent e) {
    	
    	this.repaint();
    }
    
    public void mouseEntered(MouseEvent e) {
       
    }

    public void mouseExited(MouseEvent e) {
       
    }

    public void mouseClicked(MouseEvent e) {
    	
    }
    
    public void mouseMoved(MouseEvent e) {
        
    	
    }
    
    public void mouseDragged(MouseEvent e) {
        
    	
    }
    
    public void setPanelListener(PanelListener listener){
    	this.listener=listener;
    }
    
    
    public void actionPerformed(ActionEvent e) {
    	++t_count;
    	++position;
		if(position>11){
			position=0;
		}
		
		if(t_count==40){
			timer.stop();
			listener.onHome();
			listener.onPrint();
		}
    	this.repaint();
    }
}
